<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input id="input" type="text">
    <button id="btn">go</button>
    <script>
        function define(obj, key, value) {
            observer(value)
            Object.defineProperty(obj, key, {
                get() {
                    console.log('get');
                    return value
                },
                set(newValue) {
                    console.log('set');
                    value = newValue
                }
            })
        }

        function observer(data) {
            if (data && typeof data == 'object') {
                for (let key in data) {
                    define(data, key, data[key])
                }
            }

        }
        let obj = {
            message: {
                name: 'z',
                age: 10
            }
        }
        observer(obj);

        console.log(obj.message);
    </script>

</body>

</html>